import utils


def vm_format(ip, name, data, t):
    value = str(round(float(data['value'][1]), 6))
    return name.rstrip("\n") + ":" + "vm" + ":" + ip + ":" + t + ":" + value


def collect_vm():
    msgs = []
    opts = utils.read_data("/collector_slave/config/opts/opts_vm.txt")
    names = utils.read_data("/collector_slave/config/names/names_vm.txt")
    for opt, name in zip(opts, names):
        r = utils.collect_data("localhost", opt)
        if r:
            for data in r['data']['result']:
                msgs.append(vm_format(utils.get_network_ip(), name, data, utils.get_ms_time()))
    return msgs
    # for msg in msgs:
    #     print(msg)
